//! \file Coins.cpp
//! \brief TODO: Document
// -----------------------------------------------------------------------------
//! This program is free software; you can redistribute it and/or
//! modify it under the terms of the GNU General Public License
//! as published by the Free Software Foundation; either version 2
//! of the License, or (at your option) any later version.
//!
//! This program is distributed in the hope that it will be useful,
//! but WITHOUT ANY WARRANTY; without even the implied warranty of
//! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//! GNU General Public License for more details.
//!
//! You should have received a copy of the GNU General Public License
//! along with this program; if not, write to the Free Software Foundation,
//! Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// -----------------------------------------------------------------------------

#include "Coins.h"

// =====[ Local Definitions ]===================================================

// =====[ Local DataTypes ]=====================================================

// =====[ Local Variables ]=====================================================

// =====[ Local Functions ]=====================================================

// =====[ Private (Internal) Methods ]==========================================

// =====[ Local Implementation ]================================================

namespace DnD {


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
Coins::Coins()
{
  m_Copper = 0;
  m_Silver = 0;
  m_Gold = 0;
  m_Platinum = 0;
}


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
Coins::Coins(tCOIN_COUNT Copper, tCOIN_COUNT Silver,
             tCOIN_COUNT Gold, tCOIN_COUNT Platinum)
{
  m_Copper = Copper;
  m_Silver = Silver;
  m_Gold = Gold;
  m_Platinum = Platinum;
}


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
Coins::~Coins()
{
  // TODO Auto-generated destructor stub
}


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
Coins Coins::operator+(Coins Value)
{
  Coins Result;

  // TODO: code this to ensure we don't overflow.

  // Add the coins.
  Result.m_Copper = m_Copper + Value.m_Copper;
  Result.m_Silver = m_Silver + Value.m_Silver;
  Result.m_Gold = m_Gold + Value.m_Gold;
  Result.m_Platinum = m_Platinum + Value.m_Platinum;

  // Finish up and return.
  Result.level();   // Level the results.
  return (Result);  // Return the results.
}


// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
Coins Coins::operator-(Coins Value)
{
  Coins Result;

  // TODO: implement this to ensure we can't go below 0.
  // TODO: code this to ensure we don't underflow.

  // Subtract the coins.
  Result.m_Copper = m_Copper - Value.m_Copper;
  Result.m_Silver = m_Silver - Value.m_Silver;
  Result.m_Gold = m_Gold - Value.m_Gold;
  Result.m_Platinum = m_Platinum - Value.m_Platinum;

  // Finish up and return.
  Result.level();   // Level the results.
  return (Result);  // Return the results.
}






//tCOIN_COUNT getCopper();
//tCOIN_COUNT getSilver();
//tCOIN_COUNT getGold();
//tCOIN_COUNT getPlatinum();



// =============================================================================
// Coins::getWeight
// -----------------------------------------------------------------------------
//! TODO: document
//! Determine the weight of the coins.
//! 50 pieces = 1lb.
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
tWEIGHT Coins::weight()
{
  tWEIGHT Result = 0.0f;

  // Sum the weight of all the coins.
  Result = ((tWEIGHT)m_Copper + (tWEIGHT)m_Silver +
            (tWEIGHT)m_Gold + (tWEIGHT)m_Platinum);
  Result*= m_WeightPerCoin;

  // Finally, return the weight of the coins.
  return (Result);
}



// =============================================================================
// FxName
// -----------------------------------------------------------------------------
//! TODO: document
//!
//! Conversion Table:
//!     CP      SP      GP      PP
//! CP  1       1/10    1/100   1/1000
//! SP  10      1       1/10    1/100
//! GP  100     10      1       1/10
//! PP  1000    100     10      1
//!
//! \param [in] Arg
//!   TODO: document
//!
//! \retval Exception
//!   The success status of the requested operation.
//!   - eOKAY: Execution occurred as requested.
//!   .
//!
//! \b Example: \code
//! FxName(0);
//! \endcode
// -----------------------------------------------------------------------------
void Coins::level()
{
  // Turn copper to silver.
  m_Silver+= (m_Copper / 10);
  m_Copper = (m_Copper % 10);

  // Turn silver to gold.
  m_Gold+= (m_Silver / 10);
  m_Silver = (m_Silver % 10);

  // Turn gold to platinum.
  m_Platinum+= (m_Gold / 10);
  m_Gold = (m_Gold % 10);
}


} // namespace DnD
